# coding=utf-8
import json
from api.api_trigger import ApiTrigger


def completed_handler(next_job, event, context):
    """
    :param next_job:
    :param event:
    :param context:
    :return:
    """
    print("triggered completed_handler: %s" % event)
    job_name = next_job["jobName"]
    if job_name:
        print("job name is %s..." % job_name)
        response = ApiTrigger(next_job["url"]).go()
        print("done...response is...")
        print(json.dumps(json.loads(response.text)))
        return {
            'statusCode': 200,
            'body': response.text
        }
    else:
        print("skipped trigger after flow to step %s..." % job_name)
        return {
            'statusCode': 200,
            'body': json.dumps({"msg": "skipped trigger after flow to step %s..." % job_name})
        }
